package com.jianchi.fsp.generationchildrenarithmetic;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.FloatingActionButton;
import android.support.design.widget.Snackbar;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.Menu;
import android.view.MenuItem;
import android.view.View;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;
import java.util.List;

public class ShowActivity extends AppCompatActivity {
    String extraText="";
    GenHelper gen;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_show);
        Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
        setSupportActionBar(toolbar);

        gen=(GenHelper)getIntent().getSerializableExtra("gen");

        getSupportActionBar().setDisplayHomeAsUpEnabled(true);

        ListView lv = (ListView) findViewById(R.id.lv);

        lv.setAdapter(new ArrayAdapter<String>(this, android.R.layout.simple_expandable_list_item_1,getData()));
    }

    private List<String> getData() {
        List<String> l = gen.make();
        StringBuilder sb = new StringBuilder();
        for(String s : l){
            sb.append(s).append("\r\n");
        }
        extraText = sb.toString();
        return l;
    }


    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        // Inflate the menu; this adds items to the action bar if it is present.

        getMenuInflater().inflate(R.menu.main, menu);
        return true;
    }

    @Override
    public boolean onOptionsItemSelected(MenuItem item) {
        // Handle action bar item clicks here. The action bar will
        // automatically handle clicks on the Home/Up button, so long
        // as you specify a parent activity in AndroidManifest.xml.
        int id = item.getItemId();

        if(id==R.id.action_send){
/*            Intent intent = new Intent(Intent.ACTION_SEND);
            intent.setType("image/jpg");
            intent.putExtra(Intent.EXTRA_STREAM, Uri.fromFile(ok));
            intent.putExtra(Intent.EXTRA_SUBJECT, "印章");
            intent.putExtra(Intent.EXTRA_TEXT, sc.getText());
            intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
            startActivity(Intent.createChooser(intent, "作品分享"));*/

            Intent share = new Intent(Intent.ACTION_SEND);
            share.setType("text/plain");
            String title = "小学加减口算题";
            share.putExtra(Intent.EXTRA_TEXT, extraText);
            if (title != null) {
                share.putExtra(Intent.EXTRA_SUBJECT, title);
            }
            startActivity(Intent.createChooser(share, "发送到..."));
        }

        return super.onOptionsItemSelected(item);
    }
}
